
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>管理员界面</title>
    <link rel="stylesheet" href="static/css4/bootstrap.min.css">
    <script src="static/jq/jquery.js"></script>
    <script src="static/js4/bootstrap.min.js"></script>
    <style type="text/css">
        html body {
            height: 100%;
            margin: 0;
        }

        .header-logo {
            height: 15%;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .bg-content {
            min-height: 100%;
            margin-bottom: -80px;
        }

        .bg- {
            background-color: #6495ED;
        }
    </style>
    <script type="text/javascript">
    </script>
</head>
<body>
<div class="bg-content">
    <div class="header-logo">
        <h1>欢迎来到管理员页面</h1>
    </div>
    <nav class="navbar navbar-expand-sm bg- navbar-dark">
        <div class="container d-flex flex-wrap">
            <ul class="navbar-nav">
                <li class="nav-item"><a href="${pageContext.request.contextPath}/toManagerIndex"
                                        class="nav-link link-light px-2">主页</a></li>
                <li class="nav-item"><a href="${pageContext.request.contextPath}/toStuShow"
                                        class="nav-link link-light px-2">学生信息</a></li>
                <li class="nav-item"><a href="${pageContext.request.contextPath}/toStuMistakeShow"
                                        class="nav-link link-light px-2">学生考勤信息</a></li>
                <li class="nav-item"><a href="${pageContext.request.contextPath}/toStushow"
                                        class="nav-link link-light px-2">学生考勤操作</a></li>
                <li class="nav-item"><a id="toUpload" href="#"
                                        class="nav-link link-light px-2">数据上传下载</a></li>
                <li class="nav-item"><a href="${pageContext.request.contextPath}/toUpdate"
                                        class="nav-link link-light px-2">修改个人信息</a></li>
                <li class="nav-item"><a href="${pageContext.request.contextPath}/toUpdate_pw"
                                        class="nav-link link-light px-2 active">修改密码</a></li>
                <li class="nav-item"><a href="#" class="nav-link link-light px-2">About</a></li>
            </ul>
            <ul class="navbar-nav">
                <li class="nav-item"><a href="#" class="nav-link link-light px-2"></a></li>
                <li class="nav-item">
                    <text class="nav-link link-light px-2" style="color:#000000;"><b>你好，${manager.name}</b>
                    </text>
                </li>
                <li class="nav-item"><a href="${pageContext.request.contextPath}/logout"
                                        class="nav-link link-light px-2">退出</a></li>
            </ul>
        </div>
    </nav>
    <div class="container">
        <div class="row form-div" style="text-align: center">
            <form action="${pageContext.request.contextPath}/updates_pw" method="post" name="form_update"
                class="form-horizontal" role="form">
                <div class="form-group text-center">
                    <table class="table">
                        <tr>
                            <td><span style="color: red">*</span>原密码</td>
                            <td><input id="old" class="form-control input-lg" type="password" name="amount"
                                       required></td>
                        </tr>

                        <tr>
                            <td><span style="color: red">*</span>新密码</td>
                            <td><input id="new" class="form-control input-lg" type="password" id="name" name="sname"
                                       required></td>
                        </tr>
                        <tr>
                            <td><span style="color: red">*</span>请确认</td>
                            <td><input id="new1" class="form-control input-lg" type="password" id="phone" name="sphone"
                                       required></td>
                        </tr>
                    </table>
                </div>
                <div class="form-group text-center">
                    <input id="update_pw" type="button" class="btn btn-success" value="确定"
                           style="color: #FFFFFF"/>
                </div>
            </form>
        </div>
    </div>
</div>
<div style="background-color:#fff; height:20px;margin-bottom:0px"></div>
<footer class="footer" style="background-color:#F6F7F8; height:60px;margin-bottom:0px">
    <div class="container text-center">
        <p style="text-align: center;color: #777">
            copy© 2022-2022 舒崇 版权所有
            <br><br>
        </p>
    </div>
    <div id="gotop" style="display: block;"><a class="gotop" draggable="false"></a></div>
</footer>
<script type="text/javascript">
    $("#toUpload").click(function () {
        var amount = "${manager.amount}";
        $.ajax({
            url:"${pageContext.request.contextPath}/getAuthorAmount",
            type:"POST",
            data:"amount="+amount,
            success:function(result){
                if(result.code==100){
                    console.log(result.extend.author);
                    if(result.extend.author[0].statu!=2){
                        alert("权限不足！");
                        return;
                    }else{
                        window.location.href="${pageContext.request.contextPath}/toUpload";
                    }
                }else if(result.code==200){
                    alert("权限不足！")
                }
            }
        });
    });
    $("#update_pw").click(function(){
        var amount = "${manager.amount}"
        let old = $("#old").val();
        if(old!=="${manager.password}"){
            alert("原密码错误");
            return;
        }
        let password = $("#new").val();
        let password1 = $("#new1").val();
        if(password===""){
            alert("新密码不能为空")
        }
        if(password!==password1){
            alert("两次密码输出不正确");
            return;
        }

        $.ajax({
            url:"${pageContext.request.contextPath}/update_pw",
            data: {amount:amount,password:password},
            type:"POST",
            success:function (result) {
                console.log(result)
                if(result.code==200){
                    alert("修改密码失败！")
                }else if(result.code==100){
                    alert("修改密码成功,请重新登录")

                    window.location.href="${pageContext.request.contextPath}/logout"

                }
            }
        })
    })
</script>
</body>
</html>
